   
   *! lss, lisheng2@foxmail.com, 2019-1-14
   *! 1.0 2019.1.14
   
   *cap program drop sq
   program define sq //输入项   
   version 14.0
   syntax varlist(numeric) 
    
	
	qui foreach v of varlist `varlist'{
		qui gen `v'_c = `v'
    }

     *p_ij
     qui foreach v of varlist `varlist'{
		 qui egen `v'_x=total(`v')
		 replace `v'=`v'/`v'_x
		 drop `v'_x
    }
   
    *ej
	
	qui foreach v of varlist `varlist'{
     gen `v'_t=`v'*ln(`v')
	 egen `v'_tt=total(`v'_t)
	 replace `v'=(-1)*(ln(_N))^(-1)*`v'_tt  //_N为截面个数
     drop `v'_t `v'_tt
    }
	
	*dj
	qui foreach v of varlist `varlist'{
     local n = wordcount("`varlist'")
	 gen `v'_dj=1-`v'
    }
	
	mkmat *_dj, mat(X)
	*mat list X
	mata : st_matrix("li", rowsum(st_matrix("X")))
	*mat list li
	svmat li, names(zong)
	
  
   qui local vv *_dj
      foreach v of varlist `vv'{
	      gen `v'_wj=`v'/zong
     }

	mkmat *_c , mat(X1)
	*mat list X1
	mkmat *_wj, mat(Y1)
	*mat list Y1
    mat sheng = hadamard(X1,Y1)
	*mat list sheng
	
	mata : st_matrix("z", rowsum(st_matrix("sheng")))

	*mat list z
	svmat z, names(level)
	dis in red "熵权值计算完毕"
	dis in r "熵权值存在变量levell下"
	
	qui foreach v of varlist `varlist'{
		qui drop `v'
    }
	qui drop  zong1 *_dj
	
   end
*---------------- sq.ado -------------over---




	
	
